/**
 * 
 */
package com.youth.fund.hk.hostManager.manager.dao.mybatis;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.youth.fund.hk.hostManager.common.BeanUtils;
import com.youth.fund.hk.hostManager.common.Constants;
import com.youth.fund.hk.hostManager.common.dao.mybatis.BaseMybatisDao;
import com.youth.fund.hk.hostManager.manager.dao.InformationDao;
import com.youth.fund.hk.hostManager.manager.datamodel.InformationModel;

/**
 * @author Sunk_Sky
 *
 * 2014年11月16日下午3:10:16
 */
@Repository("InformationDao")
public class InformationMybatisDaoImpl extends
		BaseMybatisDao<InformationModel, Integer> implements InformationDao
{
	private final static String CREATE_ZH_CN = "information_zh_cn.create";

	private final static String DELETE_ZH_CN = "information_zh_cn.delete";

	private final static String UPDATE_ZH_CN = "information_zh_cn.update";

	private final static String QUERY_BY_CONDITION_ZH_CN = "information_zh_cn.list_by_condition";
	
	private final static String CREATE_ZH_HK = "information_zh_hk.create";

	private final static String DELETE_ZH_HK = "information_zh_hk.delete";

	private final static String UPDATE_ZH_HK = "information_zh_hk.update";

	private final static String QUERY_BY_CONDITION_ZH_HK = "information_zh_hk.list_by_condition";
	
	private final static String CREATE_EN = "information_en.create";

	private final static String DELETE_EN = "information_en.delete";

	private final static String UPDATE_EN = "information_en.update";

	private final static String QUERY_BY_CONDITION_EN = "information_en.list_by_condition";
	
	private final static String SEARCH_BY_CONDITION_EN = "information_en.searchlist_by_condition";
	
	private final static String SEARCH_BY_CONDITION_ZH_CN = "information_zh_cn.searchlist_by_condition";
	
	private final static String SEARCH_BY_CONDITION_ZH_HK = "information_zh_hk.searchlist_by_condition";

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.common.dao.ICommonDao#create(java.io.Serializable)
	 */
	@Override
	public boolean create(InformationModel model)
	{
		Timestamp timestamp = new Timestamp(System.currentTimeMillis());

		model.setSetup_time(timestamp);

		model.setUpdate_time(timestamp);
		
		if(Constants.LANG_EN.equalsIgnoreCase(model.getLang()))
		{
			return super.create(model, CREATE_EN);
		}else if(Constants.LANG_ZH_CN.equalsIgnoreCase(model.getLang()))
		{
			return super.create(model, CREATE_ZH_CN);
		}else
		{
			return super.create(model, CREATE_ZH_HK);
		}

		
	}

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.common.dao.ICommonDao#delete(java.io.Serializable)
	 */
	@Override
	public boolean delete(InformationModel model)
	{
		if(Constants.LANG_EN.equalsIgnoreCase(model.getLang()))
		{
			return super.delete(model, DELETE_EN);
		}else if(Constants.LANG_ZH_CN.equalsIgnoreCase(model.getLang()))
		{
			return super.delete(model, DELETE_ZH_CN);
		}else
		{
			return super.delete(model, DELETE_ZH_HK);
		}
		
	}

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.common.dao.ICommonDao#update(java.io.Serializable)
	 */
	@Override
	public boolean update(InformationModel model)
	{
		Timestamp timestamp = new Timestamp(System.currentTimeMillis());

		model.setUpdate_time(timestamp);
		
		if(Constants.LANG_EN.equalsIgnoreCase(model.getLang()))
		{
			return super.update(model, UPDATE_EN);
		}else if(Constants.LANG_ZH_CN.equalsIgnoreCase(model.getLang()))
		{
			return super.update(model, UPDATE_ZH_CN);
		}else
		{
			return super.update(model, UPDATE_ZH_HK);
		}
		
	}

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.common.dao.ICommonDao#query(java.io.Serializable)
	 */
	@Override
	public List<InformationModel> query(InformationModel model)
	{
		if(Constants.LANG_EN.equalsIgnoreCase(model.getLang()))
		{
			return super.query(model, QUERY_BY_CONDITION_EN);
		}else if(Constants.LANG_ZH_CN.equalsIgnoreCase(model.getLang()))
		{
			return super.query(model, QUERY_BY_CONDITION_ZH_CN);
		}else
		{
			return super.query(model, QUERY_BY_CONDITION_ZH_HK);
		}
		
	}

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.common.dao.ICommonDao#queryOne(java.io.Serializable)
	 */
	@Override
	public InformationModel queryOne(InformationModel model)
	{
		if(Constants.LANG_EN.equalsIgnoreCase(model.getLang()))
		{
			return super.queryOne(model, QUERY_BY_CONDITION_EN);
		}else if(Constants.LANG_ZH_CN.equalsIgnoreCase(model.getLang()))
		{
			return super.queryOne(model, QUERY_BY_CONDITION_ZH_CN);
		}else
		{
			return super.queryOne(model, QUERY_BY_CONDITION_ZH_HK);
		}
		
	}

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.manager.dao.InformationDao#pageQuery(com.youth.fund.hk.hostManager.manager.datamodel.InformationModel, com.github.miemiedev.mybatis.paginator.domain.PageBounds)
	 */
	@Override
	public List<InformationModel> pageQuery(InformationModel model,
			PageBounds bound)
	{
		
		Map<String,Object> map = new HashMap<String, Object>();
		
		try
		{
			map = BeanUtils.convertBean(model);
		} catch (IllegalAccessException | InvocationTargetException
				| IntrospectionException e)
		{
			e.printStackTrace();
		}
		
		if(Constants.LANG_EN.equalsIgnoreCase(model.getLang()))
		{
			return this.sqlSesstion.selectList(SEARCH_BY_CONDITION_EN, map, bound);
		}else if(Constants.LANG_ZH_CN.equalsIgnoreCase(model.getLang()))
		{
			return this.sqlSesstion.selectList(SEARCH_BY_CONDITION_ZH_CN, map, bound);
		}else
		{
			return this.sqlSesstion.selectList(SEARCH_BY_CONDITION_ZH_HK, map, bound);
		}
	}
	
}
